package b_openApi管理.b_查询API调用额度;

import a_接口调用凭证.a_获取接口调用凭据.GetAccessToken;
import com.fasterxml.jackson.annotation.JsonProperty;
import my.wechat.rc.common.HttpClientUtil;
import my.wechat.rc.common.MapUtil;

/**
 * @author 86153
 * @date 2022/7/30
 **/
public class GetQuota {

    public static GetQuotaResponse getQuota(String cgiPath) {
        try {
            String url = "https://api.weixin.qq.com/cgi-bin/openapi/quota/get?access_token=" + GetAccessToken.getAccessToken().getAccessToken();
            return HttpClientUtil.post(url, MapUtil.of("cgi_path", cgiPath), GetQuotaResponse.class);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new GetQuotaResponse();
    }

    public static GetQuotaResponse getQuota() {
        return getQuota("/cgi-bin/message/custom/send");
    }

    public static void main(String[] args) {
        getQuota();
    }

    public static class GetQuotaResponse {
        private Integer errorcode;
        private String errmsg;
        private QuotaDetail quotaDetail;

        public Integer getErrorcode() {
            return errorcode;
        }

        public void setErrorcode(Integer errorcode) {
            this.errorcode = errorcode;
        }

        public String getErrmsg() {
            return errmsg;
        }

        public void setErrmsg(String errmsg) {
            this.errmsg = errmsg;
        }

        public QuotaDetail getQuotaDetail() {
            return quotaDetail;
        }

        public void setQuotaDetail(QuotaDetail quotaDetail) {
            this.quotaDetail = quotaDetail;
        }

        public static class QuotaDetail {
            @JsonProperty("daily_limit")
            private Integer dailyLimit;//当天该账号可调用该接口的次数
            private Integer used;//当天已经调用的次数
            private Integer remain;//当天剩余调用次数

            public Integer getDailyLimit() {
                return dailyLimit;
            }

            public void setDailyLimit(Integer dailyLimit) {
                this.dailyLimit = dailyLimit;
            }

            public Integer getUsed() {
                return used;
            }

            public void setUsed(Integer used) {
                this.used = used;
            }

            public Integer getRemain() {
                return remain;
            }

            public void setRemain(Integer remain) {
                this.remain = remain;
            }
        }
    }
}
